﻿//********************************************************************************//
//创建日期：<创建日期，2016-10-09>
//创建作者：<孙雪婷，sunxueting@shanghai3h.com>
//功能说明：水表信息查询
//********************************************************************************//
using BLL;
using BLL.Access;
using DevExpress.Export;
using DevExpress.Web;
using DevExpress.XtraPrinting;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;

namespace Web.Pages.QuShui.DiXiaS.ChaXunGL
{
    public partial class ShuiBiaoXXCX : BasePage
    {
        #region 属性

        /// <summary>
        /// 保存结果集1
        /// </summary>
        private DataTable dtShuiBiaoXX
        {
            get
            {
                return ViewState["dtShuiBiaoXX"] as DataTable;
            }
            set
            {
                ViewState["dtShuiBiaoXX"] = value;
            }
        }


        #endregion

        #region 变量

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _SpHelper = new SpHelper();
        /// <summary>
        /// 行政区
        /// </summary>
        QS_JX_XINGZHENGQBLL XZQ = new QS_JX_XINGZHENGQBLL();
       
        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitData();
            }
            this.gvShuiBiaoXX.DataSource = this.dtShuiBiaoXX;
            this.gvShuiBiaoXX.DataBind();

        }




        /// <summary>
        /// 查询信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnChaXun_Click(object sender, EventArgs e)
        {
            if (txtShuiLiangYM.Text != "")
            {
                LoadGridData();
                if (this.dtShuiBiaoXX == null || this.dtShuiBiaoXX.Rows.Count < 1)
                {
                    txtYongHuH2.Text = "";
                    txtYongHuM2.Text = "";
                    txtHuanNeiHW.Text = "";
                    txJingBianH.Text = "";
                    txtDiZhi.Text = "";
                    txtXingZhengQ.Text = "";
                    txShuiJia.Text = "";
                    txtQuShuiDZ2.Text = "";
                    txtShuiBiaoBH2.Text = "";
                    txtShuiLiangLB.Text = "";
                    txtCeHao.Text = "";
                    txtBiaoBiaoJ.Text = "";
                    txtBiaoFenL.Text = "";
                    txtZongBiaoH.Text = "";
                    memoBeiZhu.Text = "";
                    zjl.Text = "共0条";
                }
            }
        }


        

        #endregion

        #region 方法

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            int wtype = BusinessTool.WType;
            if (wtype==2)
            {
                jbh.InnerText = "井编号：";
            }
            else
            {
                jbh.InnerText = "取水口编号：";
            }
            gvShuiBiaoXX.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            //水量年月
            string water_y_m = BusinessTool.GetSLYMorZWNY(1, wtype).ToString();
            rabJingBianH.Text = wtype == 2 ? "井编号" : "取水口编号";
            //业务员
            //LoadYWY();
            txtShuiLiangYM.Text = water_y_m;

            int userid = LoginInfo.CurrentUser.UserID;//当前登陆人
            if (userid == 116 || userid == 99999 || userid == 113 || userid == 111)
            {
                btnXiuGai.Visible = true;
            }
            //加载行政区
            LoadXZQ();
            //加载业务员
            LoadYWY();
         
        }

        /// <summary>
        /// 加载行政区
        /// </summary>
        private void LoadXZQ()
        {
            DataTable dt = XZQ.SelectQS_JX_XINGZHENGQsDynamic("I_JLZT=0", null);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cmbXingZhengQ.Items.Add(dt.Rows[i]["S_XINGZHENGQM"].ToString(), dt.Rows[i]["S_XINGZHENGQH"]);
            }
        }

        /// <summary>
        /// 加载业务员
        /// </summary>
        private void LoadYWY()
        {
            PageTools.QSLoadCombox(cmbYeWuY, PageTools.eLoadType.业务员QS, null, "");
        }

        /// <summary>
        /// 加载查询数据
        /// </summary>
        private void LoadGridData()
        {
            int ym = Convert.ToInt32(txtShuiLiangYM.Text);
            int hnhw = cmbHuanNeiHW.Value != null ? Convert.ToInt32(cmbHuanNeiHW.Value) : 0;
            string xzq = cmbXingZhengQ.Text != "全部" ? cmbXingZhengQ.Value.ToString() : null;
            string ywy = cmbYeWuY.Value != null ? cmbYeWuY.Value.ToString() : "0";
            int v_bs = -1;
            string v_val = null;
            //1 用户号，2 井编号 ，3 水表编号，4 用户名，5 用户地址，6 取水地址，
            if (chkYongHuH.Checked && txtYongHuH.Text != "")
            {
                v_bs = 1;
                v_val = txtYongHuH.Text;
            }
            else if (rabJingBianH.Checked && txtJingBianH.Text != "")
            {
                v_bs = 2;
                v_val = txtJingBianH.Text;
            }
            else if (rabShuiBiaoBH.Checked && txtShuiBiaoBH.Text != "")
            {
                v_bs = 3;
                v_val = txtShuiBiaoBH.Text;
            }
            else if (chkYongHuM.Checked && txtYongHuM.Text != "")
            {
                v_bs = 4;
                v_val = txtYongHuM.Text;
            }
            else if (chkYongHuDZ.Checked && txtYongHuDZ.Text != "")
            {
                v_bs = 5;
                v_val = txtYongHuDZ.Text;
            }
           
            else if (rabQuShuiDZ.Checked && txtQuShuiDZ.Text != "")
            {
                v_bs = 6;
                v_val = txtQuShuiDZ.Text;
            }
           
            this.dtShuiBiaoXX = _SpHelper.P_QSCX_SHUIBIAOXXCX(BusinessTool.WType, ym, hnhw, xzq, ywy, v_bs, v_val, 0).Tables[0];
            gvShuiBiaoXX.DataSource = this.dtShuiBiaoXX;
            gvShuiBiaoXX.DataBind();
            if (this.dtShuiBiaoXX != null && this.dtShuiBiaoXX.Rows.Count > 0)
            {
                zjl.Text = "共" + this.dtShuiBiaoXX.Rows.Count.ToString() + "条";
                gvShuiBiaoXX.FocusedRowIndex = -1;
                gvShuiBiaoXX.FocusedRowIndex = 0;
                //SetData();
            }

        }

        /// <summary>
        /// 给显示框赋值
        /// </summary>
        private void SetData()
        {
            DataTable dt_temp = _SpHelper.P_QSCX_SHUIBIAOXXCX(BusinessTool.WType, 0, 0, "0", "0", -1, null, Convert.ToInt32(gvShuiBiaoXX.GetRowValues(0, "ID"))).Tables[0];
            if (dt_temp != null && dt_temp.Rows.Count > 0)
            {
                txtYongHuH2.Text = dt_temp.Rows[0]["S_YONGHUH"].ToString();
                txtYongHuM2.Text = dt_temp.Rows[0]["S_YONGHUM"].ToString();
                txtHuanNeiHW.Text = dt_temp.Rows[0]["HNHW"].ToString();
                txJingBianH.Text = dt_temp.Rows[0]["S_QUSHUIK"].ToString();
                txtDiZhi.Text = dt_temp.Rows[0]["S_DIZHI"].ToString();
                txtXingZhengQ.Text = dt_temp.Rows[0]["S_XINGZHENGQM"].ToString();
                txShuiJia.Text = dt_temp.Rows[0]["N_SHUIJIA"].ToString();
                txtQuShuiDZ2.Text = dt_temp.Rows[0]["S_JINGDIZ"].ToString();
                txtShuiBiaoBH2.Text = dt_temp.Rows[0]["S_SHUIBIAOBH"].ToString();
                txtShuiLiangLB.Text = dt_temp.Rows[0]["S_SHUILIANGLB"].ToString();
                txtCeHao.Text = dt_temp.Rows[0]["S_CEHAO"].ToString();
                txtBiaoBiaoJ.Text = dt_temp.Rows[0]["S_BIAOBIAOJ"].ToString();
                txtBiaoFenL.Text = dt_temp.Rows[0]["S_BIAOFENL"].ToString();
                txtZongBiaoH.Text = dt_temp.Rows[0]["S_ZONGBIAOH"].ToString();
                memoBeiZhu.Text = dt_temp.Rows[0]["S_BEIZHU"].ToString();
            }
        }

        /// <summary>
        /// 前台表格行改变事件回调方法
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            if (e.Parameter == "setinfo")
            {
                string msg = "";
                if (this.dtShuiBiaoXX != null)
                {
                    DataTable dt_temp = _SpHelper.P_QSCX_SHUIBIAOXXCX(BusinessTool.WType, 0, 0, "0", "0", -1, null, id).Tables[0];

                    msg = string.Join("|",
                        dt_temp.Rows[0]["S_YONGHUH"].ToString(),
                        dt_temp.Rows[0]["S_YONGHUM"].ToString(),
                         dt_temp.Rows[0]["HNHW"].ToString(),
                        dt_temp.Rows[0]["S_QUSHUIK"].ToString(),
                        dt_temp.Rows[0]["S_DIZHI"].ToString(),
                         dt_temp.Rows[0]["S_XINGZHENGQM"].ToString(),
                        dt_temp.Rows[0]["N_SHUIJIA"].ToString(),
                         dt_temp.Rows[0]["S_JINGDIZ"].ToString(),
                          dt_temp.Rows[0]["S_SHUIBIAOBH"].ToString(),
                          dt_temp.Rows[0]["S_SHUILIANGLB"].ToString(),
                        dt_temp.Rows[0]["S_CEHAO"].ToString(),
                         dt_temp.Rows[0]["S_BIAOBIAOJ"].ToString(),
                        dt_temp.Rows[0]["S_BIAOFENL"].ToString(),
                         dt_temp.Rows[0]["S_ZONGBIAOH"].ToString(),
                        dt_temp.Rows[0]["S_BEIZHU"].ToString()
                        );
                }

                e.Result = e.Parameter + "|0|" + msg;
            }
        }
        #endregion


        protected void btnExport_Click(object sender, EventArgs e)
        {
            //this.ASPxGridViewExporter1.GridViewID = "gvYongHuXX";
            //this.gvShuiBiaoXX.DataSource = this.dtShuiBiaoXX;
            //this.gvShuiBiaoXX.DataBind();
            string sName = txtShuiLiangYM.Text + "水表信息";
            gvShuiBiaoXX.Settings.ShowFooter = false;
            ASPxGridViewExporter1.WriteXlsToResponse(sName);
            //ASPxGridViewExporter1.WriteXlsToResponse(new XlsExportOptionsEx { ExportType = ExportType.WYSIWYG });

            
        }
    }
}